//
//  AppNetworkingManager+OAAttendance.m
//  OANetworkManager_Example
//
//  Created by TFAppleWork-Summer on 2018/2/27.
//  Copyright © 2018年 GuoRui. All rights reserved.
//

#import "AppNetworkingManager+OAAttendance.h"
#import "OAExceptionReportBrefModel.h"
#import "OAAttendanceRecordModel.h"
#import <YYModel/YYModel.h>
#import "OAExceptionReprotCommitModel.h"
@implementation AppNetworkingManager (OAAttendance)

+(TFRequest *)getAttendanceDateInfoWithDate:(long long)date complete:(void (^)(NSArray<OAExceptionReprotCommitModel*> *,
                                                                               OAAttendanceRecordModel *,
                                                                               NSError *))complete{
    
    NSDictionary *param = @{@"date" : @(date)};
    
    return [self startRequestWithParams:param
                                   path:@"attendance/getDateInfo"
                     responseObjectPath:@"data"
                  popoverProgressString:nil
               handleErrorAutomatically:OANETWORKMANAGERSHOWHUD
                          responseBlock:^(id response, NSError *error) {
                              if (!error) {
                                  NSArray *exceptinRecordDics = response[@"exceptionRecord"];
                                  NSArray *exceptinRecordModels = [OAExceptionReprotCommitModel modelWithArray:exceptinRecordDics];
                                  OAAttendanceRecordModel *attendanceRecordModel = [OAAttendanceRecordModel modelWithDict:response[@"attendanceRecord"]];
                                  complete(exceptinRecordModels,attendanceRecordModel,nil);
                              }
                              else{
                                  complete(nil,nil,error);
                              }
                          }];
}


+(TFRequest *)getExpSignWithDate:(long long)date complete:(OANetworkingObjectBlock)complete{
    
    NSDictionary *param = @{@"time" : @(date)};
    
    return [self startRequestWithParams:param
                                   path:@"attendance/expSign"
                     responseObjectPath:@"data"
                  popoverProgressString:nil
               handleErrorAutomatically:OANETWORKMANAGERSHOWHUD
                          responseBlock:^(id response, NSError *error) {
                              complete(response,error);
                          }];
    
}

+ (TFRequest *)addOrUpdateWithString:(OAExceptionReprotCommitModel *)model
                              images:(NSArray<UIImage *> *)images
                            complete:(OANetworkingObjectBlock)complete{
    
    NSDictionary *param = @{@"obj":[model yy_modelToJSONString]};    
    typeof(self) _self = self;
    return [self startRequestWithParams:param
                                   path:@"attAbm/addOrUpdate"
                       constructingBody:^(id<AFMultipartFormData>  _Nonnull formData) {
                        
                    [_self appendImageDataWithImages:images formData:formData];
                        
    }
                     responseObjectPath:@"data"
                  popoverProgressString:nil
               handleErrorAutomatically:OANETWORKMANAGERSHOWHUD
                          responseBlock:^(id response, NSError *error) {
                              OAExceptionReprotCommitModel *commitModel = [OAExceptionReprotCommitModel modelWithDict:response];
                              complete(commitModel,error);
    }];
    
}




@end
